<%@ Page Language="C#" MasterPageFile="~/admin.master" AutoEventWireup="true" Inherits="MediaMonitor.Admin.Data_Mgmt_Media"
    Theme="default" Title="Data Management - Media & Programs" CodeBehind="data-mgmt-media.aspx.cs" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server">

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script src="../rad-scripts/rad.js" type="text/javascript"></script> 
    </telerik:RadCodeBlock>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" Runat="Server">
    <telerik:RadAjaxPanel ID="radPanel" runat="server" RestoreOriginalRenderDelegate="false">
        <div>
            <table>
        <tr>
            <td><b>Select Media Type:</b> </td>
            <td>
             <asp:DropDownList ID="lstMediaType" runat="server"  AutoPostBack="true" OnSelectedIndexChanged="lstMediaType_SelectedIndexChanged"></asp:DropDownList>
            </td>
            <td>
                New Media Code
               <%-- <asp:RequiredFieldValidator ID="rfvMediaCode" runat="server" ControlToValidate="tbMediaCode" Text="*" ErrorMessage="Plz Enter Media Code" Display="Dynamic" ValidationGroup="form" />
                <asp:RangeValidator ID="rvMediaCode" runat="server" ControlToValidate="tbMediaCode" Text="Invalid number" ErrorMessage="Invalid Number" Display="Dynamic" Type="Integer" MinimumValue="1" MaximumValue="9999999" ValidationGroup="form" />--%>
            </td>
            <td>
                <asp:TextBox ID="tbMediaCode" runat="server" ValidationGroup="form"></asp:TextBox>
            </td>
            <td>
                New Media
                <%--<asp:RequiredFieldValidator ID="rfvMediaName" runat="server" ControlToValidate="tbMediaName"
                    Text="*" ErrorMessage="Plz Enter Media Name" Display="Dynamic" ValidationGroup="form" />--%>
            </td>
            <td>
                <asp:TextBox ID="tbMediaName" runat="server" ValidationGroup="form"></asp:TextBox>
            </td>
            <td>
                <asp:Button ID="btnAddNew" runat="server" Text="Add New" OnClick="btnAddNew_Clicked" ValidationGroup="form" />
            </td>
        </tr>
    </table>
       
        <asp:SqlDataSource ID="sqlDSMediaType" runat="server" ConnectionString="<%$ ConnectionStrings:DBAdex%>" SelectCommand="SELECT MediaTypeCode, MediaTypeName FROM MediaType" />


        <br /><br />

        Click the
        <img src="../App_Themes/default/cssimg/exapand.png" alt="loading" style="display: inline;" />
        link at the left side of records to expand the data.
        <br />
    </div>
    <div style="padding: 5px; width: 90%;">
        <telerik:RadGrid ID="radGrid" runat="server" AllowFilteringByColumn="True" AllowPaging="True" 
            AllowSorting="True" GridLines="None" Skin="Hay"  AllowAutomaticUpdates="true"
            Width="100%" AutoGenerateColumns="false" GroupingSettings-CaseSensitive="false" DataSourceID="SqlDataSource1"
            PageSize="50" OnDeleteCommand="radGrid_DeleteCommand">  <%--OnUpdateCommand="radGrid_UpdateCommand"  OnNeedDataSource="radGrid_NeedDataSource"--%>
          
        <MasterTableView DataKeyNames="MediaCode" ExpandCollapseColumn-Display="true" DataSourceID="SqlDataSource1"   DetailKeyField="MediaCode" GroupLoadMode="Client">
         <EditFormSettings>
      <EditColumn UniqueName="EditCommandColumn1" />
      <PopUpSettings ScrollBars="None" />
    </EditFormSettings>
            <Columns>
                <telerik:GridButtonColumn Text="Delete" ButtonType="LinkButton" ConfirmText="Are you sure to delete this record?" ConfirmTitle="Delete Confirmation" CommandName="Delete" />
                 <telerik:GridButtonColumn Text="Edit" ButtonType="LinkButton"  CommandName="Edit" />
                <telerik:GridBoundColumn  AutoPostBackOnFilter="true" DataField="MediaCode" HeaderText="Media Code" />
                <telerik:GridBoundColumn  AutoPostBackOnFilter="true" DataField="MediaName" HeaderText="Media Name" />
                <telerik:GridBoundColumn  AutoPostBackOnFilter="true" DataField="LastModifiedDate" HeaderText="Last Modified" HtmlEncode="false" DataFormatString="{0:d}" />
            </Columns>
            
            <DetailTables>
                <telerik:GridTableView DataKeyNames="ProgramCode" AutoGenerateColumns="false" Caption="" AllowSorting="true"
                    PageSize="10" DataSourceID="sqlDSProg">
                    <ParentTableRelation>
                        <telerik:GridRelationFields MasterKeyField="MediaCode" DetailKeyField="MediaCode" />
                    </ParentTableRelation>
                    <ItemStyle CssClass="Level2Item"/>
                    <AlternatingItemStyle CssClass="Level2AltItem" />
                    <FilterItemStyle BackColor="#898989" ForeColor="White" />
                    <Columns>
                        <telerik:GridButtonColumn Text="Delete" ButtonType="LinkButton" ConfirmText="Are you sure to delete this record?" ConfirmTitle="Delete Confirmation" CommandName="Delete" />
                        <telerik:GridBoundColumn  AutoPostBackOnFilter="true" DataField="ProgramCode" HeaderText="Program Code" />
                        <telerik:GridBoundColumn  AutoPostBackOnFilter="true" DataField="ProgramName" HeaderText="Program" />
                        <telerik:GridBoundColumn  AutoPostBackOnFilter="true" DataField="DateModified" HeaderText="Last Modified" HtmlEncode="false"
                            DataFormatString="{0:d}" />
                    </Columns>
                    
                </telerik:GridTableView>
                
            </DetailTables>
            
        </MasterTableView>
            <ClientSettings>
                <Scrolling AllowScroll="false" />
                <ClientEvents OnFilterMenuShowing="filterMenuShowing" />
            </ClientSettings>
            <FilterMenu OnClientShowing="MenuShowing" />
    </telerik:RadGrid>
      
    </div>
      </telerik:RadAjaxPanel>
    
      <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DBAdex %>"
       SelectCommand="SELECT * , CONVERT(VARCHAR, DateModified, 101) AS LastModifiedDate  from Medium WHERE MediaTypeCode=@MediaTypeCode" 
        UpdateCommand="Update Medium set MediaName=@MediaName where MediaCode=@MediaCode">
        <SelectParameters>
            <asp:ControlParameter ControlID="lstMediaType" DefaultValue="1" 
                Name="MediaTypeCode" PropertyName="SelectedValue" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="MediaName"  Type="String"/>
            <asp:Parameter Name="MediaCode"  Type="Int32"/>
        </UpdateParameters>
    </asp:SqlDataSource>

   
    <asp:SqlDataSource ID="sqlDSProg" runat="server" ConnectionString="<%$ ConnectionStrings:DBAdex %>"
    
        SelectCommand="SELECT * FROM Program WHERE MediaCode = @MediaCode ORDER BY ProgramName" >
       
        <SelectParameters>
            <asp:Parameter Name="MediaCode" DefaultValue="0" Type="Int32" />
        </SelectParameters>
       
    </asp:SqlDataSource>
</asp:Content>

